// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 

package com.anda.driver.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.anda.driver.util.data.RegisterInfo;

public class Constant
{

	public final static String TAG = "com.anda.driver.locator";
	public static final String ProdName = "com.anda.driver.locator";
	public static final String Baidu_Key = "1D06E19C5A75CD529ECF5D24C1B087DCD5A2847F";
	public static long cellMinTime = 40 * 60 * 1000L;
	public static long cellNoResultTime = 15 * 60 * 1000L;
	public static long gpsMinTime  = 60 * 60 * 1000L;
	//public static String LOGIN_USERNAME = null;
	public static RegisterInfo REGISTER_INFO = null;
	
	public Constant()
	{
	}

	public static long max(long n1, long n2){
		return (n1 >= n2 ? n1: n2);
	}
	public static long min(long n1, long n2){
		return (n1 >= n2 ? n2: n1);
	}
	
	public static void debug(String s)
	{
		Log.d(TAG, s);
	}

	public static String getNetType(Context context)
	{
		String s = "";
		NetworkInfo networkinfo = ((ConnectivityManager)context.getSystemService("connectivity")).getActiveNetworkInfo();
		if (networkinfo != null && networkinfo.isAvailable())
			if (networkinfo.getExtraInfo() == null)
				s = "";
			else
			if (networkinfo.getExtraInfo().indexOf("wap") <= 0)
				s = "";
			else
				s = "wap";
		return s;
	}

		public static String getProvider(Context context)
	{
		String s = "";
		try {
			String s1 = ((TelephonyManager)context.getSystemService("phone")).getNetworkOperatorName();
			if (s1 != null) {
				return s1;
			} 
		} catch (Exception e) {
			e.printStackTrace();
		}
		return s;
		
	}

	public static String getTimestamp(long l)
	{
		return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date(l));
	}
	
	private static long getTimeBefore (long time, int days){
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(time);
		//cal.ad
		cal.add(Calendar.DAY_OF_MONTH, -1 * days);
		return cal.getTimeInMillis();
	}
	
	public static void main(String[] args) throws ParseException{
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date d = format.parse("2012-07-26 10:30:00");
		long t = getTimeBefore(d.getTime(), 30);
		d.setTime(t);
		System.out.println(format.format(d));
	}
	
	public static long getTimeFromStr(String str){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date d = new Date();
		try {
			d = format.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return d.getTime();
	}
	
	public static String encode(String s){
		if ( null == s) return null;
		String r = null;
		try {
			r = URLEncoder.encode (URLEncoder.encode(s, "utf-8"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return r;
	}

}
